package com.app.service.impl;

import com.app.mapper.PolicyRequireMapper;
import com.app.model.PolicyRequireModel;
import com.app.service.PolicyRequireService;
import com.app.vo.PolicyRequireVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PolicyRequireServiceImpl extends ServiceImpl<PolicyRequireMapper, PolicyRequireModel> implements PolicyRequireService {
    @Autowired
    private PolicyRequireMapper policyRequireMapper;
    @Override
    public PolicyRequireVo getPolicyRequireList(Integer page, Integer limit) {

        Page<PolicyRequireModel> page1 = new Page<>(page, limit);
        Page<PolicyRequireModel> policyRequirePage = policyRequireMapper.selectPage(page1, null);
        List<PolicyRequireModel> policyRequireList = policyRequirePage.getRecords();
        long count = policyRequirePage.getTotal();

        PolicyRequireVo policyRequireVo = new PolicyRequireVo();
        policyRequireVo.setList(policyRequireList);
        policyRequireVo.setCount((int) count);
        return policyRequireVo;
    }
    //根据类型查
    @Override
    public PolicyRequireVo getByType(Integer type,Integer page,Integer limit) {


        Page<PolicyRequireModel> page1 = new Page<>(page, limit);
        LambdaQueryWrapper<PolicyRequireModel> lqw =new LambdaQueryWrapper();
        lqw.eq(PolicyRequireModel::getType,type);
        Page<PolicyRequireModel> policyRequirePage = policyRequireMapper.selectPage(page1, lqw);
        List<PolicyRequireModel> policyRequireList = policyRequirePage.getRecords();

        long count = policyRequirePage.getTotal();
        PolicyRequireVo policyRequireVo = new PolicyRequireVo();
        policyRequireVo.setList(policyRequireList);
        policyRequireVo.setCount((int) count);
        return policyRequireVo;
    }
}
